//
//  UIControl+point.m
//  Test
//
//  Created by xueshan1 on 2019/6/5.
//  Copyright © 2019 xueshan1. All rights reserved.
//

#import "UIControl+point.h"
#import "NSObject+swizzle.h"
@implementation UIControl (point)

+ (void)load{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self swizzleInstanceMethod:@selector(sendAction:to:forEvent:) newSelector:@selector(my_sendAction:to:forEvent:) class:[self class]];
    });
}

- (void)my_sendAction:(SEL)action to:(id)target forEvent:(UIEvent *)event{
    
    NSLog(@"打点 sel:%@ target:%@",NSStringFromSelector(action),target);
    
    if (event.type == UIEventTypeTouches) {
        UITouch *touch = [event.allTouches anyObject];
        if (touch.phase == UITouchPhaseBegan) {
           CGPoint point = [touch locationInView:[UIApplication sharedApplication].keyWindow];
            NSLog(@"control begin:%@",NSStringFromCGPoint(point));
        }else if (touch.phase == UITouchPhaseMoved){
            
        }else if (touch.phase == UITouchPhaseEnded){
            CGPoint point = [touch locationInView:[UIApplication sharedApplication].keyWindow];
            NSLog(@"control end:%@",NSStringFromCGPoint(point));
        }
        
    }
    

    [self my_sendAction:action to:target forEvent:event];
}
@end
